<template>
  <page-frame>
    <div class="check02-in-main" style="vertical-align: top">
      <div class="toptitle">
        <div class="left">健康评估 - 评估详情</div>
        <div class="right">
          <div class="btns">
            <el-button @click="back">返回</el-button>
          </div>
        </div>
      </div>
      <div style="border-bottom: 1px solid #ccc;height: 1px; margin:8px 0px 20px 0px;"></div>
      <!--基本信息-->
      <el-form>
        <div class="panel">
          <div class="panel-title">
            <el-row :gutter="20">
              <el-col :span="6">
                <div class="grid-content bg-purple">基本信息</div>
              </el-col>
            </el-row>
          </div>
          <el-row>
            <el-col :span="12">
              <el-form-item label="会员姓名">
                <el-input v-model="this.currentMemberObj.memberName"  disabled></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="12">
              <el-form-item  label="评估量表">
                <el-input v-model="this.currentMemberObj.sheetName" disabled></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <div class="panel-title">
            <el-row :gutter="20">
              <el-col :span="6">
                <div class="grid-content bg-purple">评估信息</div>
              </el-col>
            </el-row>
          </div>
          <div class="ability">
            <el-collapse v-model="activeName" @change="handleChange">
              <el-collapse-item v-for="accessItems in ASSESS_ITEM" :name="accessItems.setId">
                <template slot="title">
                  {{accessItems.setName}} <i v-if="accessItems.complete == 0" style="color: gray;">未完成</i>
                  <i v-else-if="accessItems.complete == 1" style="color: green;">已完成</i>
                </template>
                <div class="assessmentContent" v-for="accessItem in accessItems.assessItemDTOList">
                  <div class="assessmentTitle" >
                    <label>{{accessItem.itemNo}}.{{accessItem.itemTitle}}</label>
                  </div>
                  <div class="assessmentItem">
                    <options :options="accessItem.assessItemResultDTOList"
                             :type="accessItem.type"
                             :other="accessItem.other"
                             :itemId="accessItem.itemId"
                             :setId = "accessItem.setId"
                             :optionsDisabled = "optionsDisabled"
                             @updateOption = "updateOption"
                    ></options>
                  </div>
                </div>
                <div class="assessmentMark">
                  <reference :reference="accessItems.assessSetResultDTOList"></reference>
                </div>
                <div class="assessmentInput">
                  <inputs :results = "results"
                          :setresult = "accessItems.assessmentResultDTO"
                          :setId= "accessItems.setId"
                          :careJudgment = "accessItems.assessSetResultDTOList"
                          :member = "this.currentMemberObj"
                          :optionsDisabled = "optionsDisabled"
                  ></inputs>
                </div>
              </el-collapse-item>
            </el-collapse>
            <div class="examine-result"  v-show="isPingguShow">
              <el-button type="info" class="lightGreenBtn" :disabled="disabled" @click="getResult">查看评估结果</el-button>
              <!--<el-button type="info" :disabled="disabled" @click="isPlan">制定服务计划</el-button>-->
            </div>
            <div class="evaluation-result" v-show="isResultShow">
              <resultSheet :resultEvaluation = "resultEvaluation" :member="this.currentMemberObj"  :resultHealthy="results" :optionsDisabled = "optionsDisabled"  @goto="goto"></resultSheet>
            </div>
          </div>

        </div>
      </el-form>
    </div>
  </page-frame>
</template>

<script>
  import checkInApi from '../../service/member/checkInApi'
  import options from '../../components/assessment/abilityContent/options';
  import inputs from '../../components/assessment/abilityContent/inputs';
  import reference from "../../components/assessment/abilityContent/reference";
  import resultSheet from "../../components/assessment/abilityContent/resultSheet";
  import planMake from "../../components/assessment/planMake";;
  import commonApi from '../../service/member/commonApi';

  export default {
    props:["isChange"],
    data(){
      return{
        currentStatus:null,
        optionsDisabled:"",
        sheetType:"",
        memberId:"",
        currentMemberObj:{
          memberName:'',
          actId:1,
        },
        isResultShow:false,
        isPingguShow:"",
        isSubmit:false,
        disabled:false,
        activeName:"1",
        radio2: 3,
        currentView:"resultSheet",
        currentAccessId:0,
        assessId:"",
        sheetId:0,
        itemResult:[],
        ASSESS_ITEM:[],
        results:{
          "assessId": 0,
          "auditTime": "",
          "auditUser": "",
          "comment": "",
          "itemResultVOList": [],
          "rId": 0,
          "resultValue": 0,
          "setId": 0,
          "sheetId": 0,
          "resultName":""
        },
        resultEvaluation:{
          "assessmentResultDTO": {},
          "setResultInfoDTOList": [],
          "sheetResultDTOList": [],
        },
        careLevelOptions:null
      }
    },
    methods: {
      init(){
        let self = this;
        self.currentMemberObj=self.$route.params.memberObj; //获取url地址的对象
        self.currentStatus=self.$route.params.status;
        self.currentMemberObj.actId=1;
        /**
         * 判断是否是详情或者是继续  1是继续
         */
        if(self.currentStatus=="1"){
          self.optionsDisabled=false;
        }
        else{
          self.optionsDisabled=true;
        }
        if(typeof self.currentMemberObj=="object"){
          self.assessId=self.currentMemberObj.assessId;
          self.sheetType=self.currentMemberObj.sheetType;
          self.memberId=self.currentMemberObj.memberId;
          self.loadProject(self.sheetType,self.memberId);
        }else{
          self.$router.push({name: 'memberCheckIn'});
        }

        //  this.affirmCurrentTasId = this.currentTasId;
      },
      handleChange(){

      },
      back(){
        this.$router.push({name: 'healthAssessment'});
      },
//      /**
//       *获取评估项目
//       */
      loadProject(sheetType,memberId){
        debugger
        let self = this;
        checkInApi.getPingguResult(self.assessId).then(function (response) {
          var data = response.body.data;
          if (data) {
            self.ASSESS_ITEM = data.assessSetDTOList;
            var remain = 0;
            self.ASSESS_ITEM.forEach(function (accessItems) {
              if (!accessItems.assessmentResultDTO) {
                if (accessItems.complete == 0) {
                  remain += 1;
                }
                accessItems.assessmentResultDTO = {
                  "assessId": "0",
                  "auditTime": "",
                  "auditUser": "",
                  "comment": "",
                  "rId": 0,
                  "resultValue": 0,
                  "setId": 0,
                  "sheetId": 0
                }
              }
            });
            self.results.assessId = data.assessId;
            self.results.sheetId = data.sheetId;
            self.isPingguShow = true;
            if (remain == 0) {
              self.getResult();
            }
          }
          else {
            self.isPingguShow = false;
            self.$message.info('评估量表不存在!');
            return false;
          }
        });
      },
      goto(taskKey){
        this.$emit("goto",taskKey);
      },
      /**
       *获取评估信息
       */
      getProjectDetail(sheetType,memberId){
        let self = this;
        checkInApi.getProjectDetail(sheetType,memberId).then(function(response){
          self.ASSESS_ITEM = response.body.data;
        });
      },
      /**
       * 查看评估结果
       */
      getResult(){
        let self = this;
        self.currentView = "resultSheet";
        checkInApi.getAResult(self.results.assessId).then(function (response) {
          self.resultEvaluation = response.body.data;
          self.isResultShow = true;
        })
      },
      /**
       *
       *获得答案（子组件）
       */
      updateOption(val){
        if(val.itemId){
          for(var i=0;i<this.results.itemResultVOList.length;i++){
            if(this.results.itemResultVOList[i].itemId == val.itemId){
              this.results.itemResultVOList.splice(i,1);
            }
          }
          this.results.itemResultVOList.push(val);
        }
      },

    },
    components:{options,inputs, reference, resultSheet,planMake},
    mounted: function () {
      this.init();
    }
  }
</script>

<style>

  .tabs .tabsTitle > li {
    font-size: 14px;
    display: inline-block;
    background-color: #a8a8b0;
    width: 33.2%;
    padding-top: 10px;
    padding-bottom: 10px;
    border-left: 1px solid #ffffff;
    text-align: center;
    cursor: pointer;
    color: #ffffff;
  }

  .input input {
    display: inline-block;
  }

  .check02-in-main .assessmentTitle{
    padding-bottom: 10px;
    font-size: 14px!important;
  }
  .check02-in-main .assessmentItem{
    padding-left: 15px;
    font-size: 14px!important;
  }
  .check02-in-main .assessmentItem label{
    display: block;
  }
  .check02-in-main .assessmentItem .el-radio+.el-radio,.el-checkbox+.el-checkbox{
    margin: 12px 0px!important;
  }
  .check02-in-main .assessmentItem textarea{
    width: 50%;
  }
  .check02-in-main .evaluation-result{
    background-color: #F2F8FE;
    padding:30px 60px;
  }
  .check02-in-main .examine-result{
    margin:20px;
  }

  .check02-in-main .reference{
    margin-bottom:7px;
  }
  .check02-in-main .assessmentInput{
    margin-top:20px;
  }
  .check02-in-main .assessmentInput label{
    margin-right:7px;
  }
  .check02-in-main .assessmentInput .el-row{
    margin-bottom:7px;
  }
  .check02-in-main .fen{
    color: #20a0ff;
    cursor: pointer;
  }
  .check02-in-main .fen:hover{
    color: #3fc6d2;
    cursor: pointer;
  }
</style>
